﻿using System;
using System.Collections.ObjectModel;
using System.Text;
using MUD.Lib.Utils;
using MUD.Lib.Objects.Rooms;

namespace MUD.Lib.Objects.Domains
{
    /// <summary>
    /// A Domain is the physical representation of an "area" and functions as a logical grouping of rooms
    /// for various purposes, such as area chat, separation of concerns and such.
    /// </summary>
    internal class Domain
    {
        protected Collection<Room> RoomList = new Collection<Room>();
        protected Type StartRoom;
        public string DomainName;

        public int RoomCount
        {
            get { return RoomList.Count; }
        }

        public Room Start
        {
            get
            {
                foreach (Room room in RoomList)
                {
                    if (room.GetType() == StartRoom)
                        return room;
                }
                return null;
            }
        }

        public Room this[Type roomType]
        {
            get
            {
                foreach (Room room in RoomList)
                {
                    if (room.GetType() == roomType)
                        return room;
                }
                return null;
            }

            set
            {
                if (!RoomList.Contains(value))
                    RoomList.Add(value);
            }
        }

        public Domain()
        {

        }

        public virtual void Initialize()
        {

            if (StartRoom != null && StartRoom.IsSubclassOf(Type.GetType("MUD.Lib.Objects.Rooms.Room")))
            {
                Room start = (Room)Activator.CreateInstance(StartRoom, new object[] {this});
                //RoomList.Add(start);
            }
            
                
        }

    }
}
